// 引入Count的UI组件
import CountUI from '../../components/Count';

// 引入action
import {
    createIncrementAction,
    createDecrementAction,
    createIncrementAsyncAction,
} from '../../redux/count_action';

// 引入connect用户连接UI组件和redux
import { connect } from 'react-redux';

// a函数的返回值作为状态传递给了UI组件
function mapStateToProps(state) {
    return { count: state };
}

// b函数的返回值是操作状态的方法
function mapDispatchToProps(dispatch) {
    return {
        jia: number => dispatch(createIncrementAction(number)),
        jian: number => dispatch(createDecrementAction(number)),
        jianAsync: (number, time) => dispatch(createIncrementAsyncAction(number, time)),
    };
}

export default connect(mapStateToProps, mapDispatchToProps)(CountUI);
